package jianzhi;

import niuke.ListNode;

import java.util.Stack;

/**
 * description:
 * author:zt
 * date:2021-10-17
 */
/*
输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 */
public class jianzhi06 {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        while (head!=null){
            stack.push(head.val);
            head = head.next;
        }
        int[] res = new int[stack.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = stack.pop();
        }
        return res;
    }
}
